package com.xy.blog.core.verificate;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;

/**
 * @author zanhonglei
 * @version V1.0
 * @Description: SpringMVC 请求参数校验
 * TODO 需要做优化 ,通过AOP + 自定义注解实现
 * @date 2019/11/10 2:07 上午
 */
@Component
@Aspect
public class ParameterValidAop implements Ordered {

    /**
     * 需要根据某个模块定制配置
     * @param pjp
     * @param bindingResult
     * @return
     * @throws Throwable
     */
    @Around("execution(* com.xy.blog.*.controller.*Controller.*(..)) && args(..,bindingResult)")
    public Object validateParam(ProceedingJoinPoint pjp, BindingResult bindingResult) throws Throwable {
        Parameter.checking(bindingResult);
        return pjp.proceed();
    }

    @Override
    public int getOrder() {
        return 10;
    }
}
